package com.neusoft.demo7;

/**
 * 主人类
 */
public class Master {
    public void cure(Pet pet) { //pet = Dog
        if(pet.getHealth()<50) {
            pet.toHospital();
        }
    }
    public void play(Pet pet) {
        if(pet instanceof Dog){ //如果dog与pet有继承关系，返回true
            Dog dog = (Dog) pet; //子类中新扩充的方法对于父类是不可见的，一定要强制类型转换
            dog.catchingFly();
        }else if(pet instanceof Penguin) {
            Penguin penguin = (Penguin) pet;
            penguin.swimming();
        }
    }
    public static void main(String[] args) {
        Master master = new Master();
        Dog dog = new Dog();
        dog.setHealth(30);
        master.cure(dog);
        master.play(dog);
        Penguin penguin = new Penguin();
        penguin.setHealth(30);
        master.cure(penguin);
        master.play(penguin);

    }
}
